<?php
###########################################################################
## index.php - Skapar en meny av filer och mappar i den mapp den ligger. ##
## Ändr: 20151101.0845.di rev. 20151205.0755di                           ##
###########################################################################
## Configuration ##
/*************************************************************************/
$rubbe = "Rubrik";
$show_path = FALSE;    # Visa "local path".
$show_dotdirs = FALSE; # Visa "Tillbaka" ('.' and '..').
$extensions = " .php.svg.svgz.ico.jp2.jpc.old.xxx"; # VISA EJ
$nocount = " .zip.html"; # Räknas ej
$nofiles = " .. robots.txt Bildindex.jpg +Bildindex.html"; # VISA EJ
$nodirs =" utlyft stats css js error"; # VVISA EJ dessa mappar
###########################################################################
$path = substr($_SERVER['SCRIPT_FILENAME'], 0,
        strrpos($_SERVER['SCRIPT_FILENAME'], '/') + 1);
$dirs   = array();
$files  = array();
$dir    = dir($path);
$bildnr = "0";
?>
<html>
  <head>
    <title><?php echo $rubbe; ?></title>
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
    <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="cache-control" CONTENT="no-cache" />
    <meta HTTP-EQUIV="cache-control" CONTENT="max-age=0" />
    <meta HTTP-EQUIV="expires" CONTENT="0" />
    <link REL="shortcut icon" HREF="../favicon.ico" TYPE="image/x-icon">

<!--
  *****  Style-variant för bakgrundsbild i body *****
      body {
        margin: 0;
        background-image: url("./bildnamn.svg");
        background-size: cover;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-repeat: no-repeat;
      }
-->

    <style type="text/css">
      body {
        font-family: Verdana, Arial, sans-serif;
        margin: 40px;
        text-align: center;
        background-color: #888888;
      }

      a:link {
        color: #000000;
        text-decoration: none;
      }
      a:visited {
        color: #000000;
        text-decoration: none;
      }
      a:hover {
        color: #666666;
        text-decoration: none;
      }
      a:active {
        color: #660000;
        text-decoration: none;
      }

      table {
        background-color: #222222;
        border: #cccccc solid 1px;
        border-spacing: 1px;
        width: 480px;
      }
      th {
        background-color: #4466aa;
        color: #ffffff;
        font-size: 12pt;
        font-weight: bold;
        text-align: left;
        padding: 4px;
      }
      td {
        background-color: #efef8f;
        color: #000000;
        font-size: 10pt;
        font-weight: normal;
        padding: 10px;
      }
            
      h2 {
        font-family: Verdana, Arial, sans-serif;
		    color: #000000;
        font-size: 22pt;
        font-weight: bold;
        text-align: center;
        text-decoration: none;
 	  }
    </style>    
  </head>
  <body>
<!--    <h3>Eventuell arkivrubrik här</h3> -->
    <table cellspacing="1">
      <tr>
        <th><?php if ($show_path == 1) { echo $path; } else { echo $rubbe; } ?></th>
      </tr>
      <tr>
        <td>
          <?php

          while ($entry = $dir->read()) {
            if (($entry != '.') and !(strpos($extensions, substr($entry, -4)))) {
              if (is_dir($entry)) {
                if (($entry != '..') or $show_dotdirs){
                  $dirs[] = $entry;
                }
              } else {
                $files[] = $entry;
              }
            }
          }
          $dir->close();

          sort($dirs);
          foreach ($dirs as $dir) {
            if ($dir == "..")
              printf('<a href="%s"><font size="3"><b>%s</b></font></a><br />' . "\n", $dir, "&#8678; Tillbaka");
            else if (strpos($nodirs, $dir))
              continue;
            else
              printf('<b><</b><a href="%s"><font size="2"><b>%s</b></font></a><b>></b><br />' . "\n", $dir, $dir);
###              printf('<b><</b><a href="%s">%s</a><b>></b><br />' . "\n", $dir, $dir);
          }

          sort($files);
          foreach ($files as $file) {
            if ($file == "+Bildindex.html"){
              printf('<a href="%s"><font size="3"><b>%s</b></font></a><br />' . "\n", $file, "Kontaktkarta");
              continue;
            }else if (strpos($nofiles, $file))
              continue;
            else if (!(strpos($nocount, substr($file, -4)))) # Numrera
	          $bildnr ++; # Numrera inte
            printf('<a href="%s">%s.&ensp;%s<br />' . "\n", $file, $bildnr, $file);
          }
          ?>
        </td>
      </tr>
    </table>
  </body>
</html>
